package com.fwj.user.strategy;

import com.fwj.core.common.model.ResponseDTO;
import com.fwj.user.model.user.UserDetailsInfo;
import com.fwj.user.strategy.impl.UserStrategyImpl;


/**
 * @Author: fwj
 * @Data: 2022/4/19 21:26
 * @Version 1.0
 * @Description: 用户策略
 */


public enum UserStrategy {
    //策略枚举
    /**
     * 个人界面
     */
    PERSONAL_INTERFACE("Personal Interface", UserStrategyImpl.PERSONAL_INTERFACE),
    /**
     * 我的头像
     */
    PROFILE_PHOTO("Profile Photo", UserStrategyImpl.PROFILE_PHOTO),
    /**
     * 我的成就
     */
    ACHIEVEMENT("Achievement", UserStrategyImpl.ACHIEVEMENT),
    /**
     * 账号安全
     */
    ACCOUNT_SECURITY("Account Security", UserStrategyImpl.ACCOUNT_SECURITY),
    /**
     * 登录记录
     */
    LOGIN_RECORD("Login Record", UserStrategyImpl.LOGIN_RECORD),
    /**
     * 实名认证
     */
    REAL_NAME_AUTHENTICATION("Real Name Authentication", UserStrategyImpl.REAL_NAME_AUTHENTICATION),
    /**
     * 我的钱包
     */
    MY_WALLET("My Wallet", UserStrategyImpl.MY_WALLET),
    /**
     * 创作中心
     */
    CREATIVE_CENTER("Creative Center", UserStrategyImpl.CREATIVE_CENTER),
    /**
     * 我的会员
     */
    MY_VIP("My Vip", UserStrategyImpl.MY_VIP),
    ;

    private final UserStrategyImpl userStrategyImpl;

    private final String strategy;

    //策略构造
    UserStrategy(String strategy, UserStrategyImpl userStrategyImpl) {
        this.strategy = strategy;
        this.userStrategyImpl = userStrategyImpl;
    }

    //获取策略
    public String getStrategy() {
        return strategy;
    }

    //策略执行
    public ResponseDTO execStrategy(UserDetailsInfo userDetailsInfo, boolean isQuery) throws Exception {
        if (isQuery){
            return userStrategyImpl.execQuery(userDetailsInfo);
        }else {
            return userStrategyImpl.execUpdate(userDetailsInfo);
        }
    }

    //匹配策略，可优化
    public static UserStrategy matchStrategy(String strategy) {
        for (UserStrategy userStrategy : UserStrategy.values()) {
            //返回匹配成功的策略
            if (userStrategy.getStrategy().equals(strategy)) {
                return userStrategy;
            }
        }
        return null;
    }
}
